package com.markerhub.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.markerhub.common.lang.Result;
import com.markerhub.entity.ManagerActivity;
import com.markerhub.entity.ManagerTeacher;
import com.markerhub.mapper.ManagerActivityMapper;
import com.markerhub.service.ManagerActivityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;


@Service
public class ManagerActivityServiceImpl extends ServiceImpl<ManagerActivityMapper, ManagerActivity> implements ManagerActivityService {

    @Override
    public ManagerActivity getByActivityName(String activityName) {
        // 使用 MyBatis-Plus 查询构造器，通过 teachername 字段查询
        return this.getOne(new LambdaQueryWrapper<ManagerActivity>().eq(ManagerActivity::getName, activityName));
    }

    @Override
    public IPage getActivities(String title, Integer status, int currentPage, int pageSize) {
        Page<ManagerActivity> page = new Page<>(currentPage, pageSize);

        QueryWrapper<ManagerActivity> queryWrapper = new QueryWrapper<>();
        if (title != null && !title.isEmpty()) {
            queryWrapper.like("title", title); // 模糊查询标题
        }
        if (status != null) {
            queryWrapper.eq("status", status); // 查询状态
        }
        queryWrapper.orderByDesc("created_time"); // 按照创建时间降序排序

        IPage page1 = this.page(page, queryWrapper);
        return page1;
    }
}
